package xin.marcher.module.price.api.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.exception.ProductBizException;
import xin.marcher.module.price.api.SkuPriceApi;
import xin.marcher.module.price.domain.dto.SkuPriceSellerRelationDTO;
import xin.marcher.module.price.domain.request.SkuPriceRequest;
import xin.marcher.module.price.service.SkuPriceSellerRelationService;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Slf4j
@DubboService(version = "1.0.0", interfaceClass = SkuPriceApi.class, retries = 0)
public class SkuPriceApiImpl implements SkuPriceApi {

    @Resource
    private SkuPriceSellerRelationService skuPriceSellerRelationService;

    /**
     * 根据skuID和sellerId获取价格信息，包括不同类型的价格（商城价、会员价）
     *
     * @param request
     * @return 价格信息
     */
    @Override
    public JsonResult<List<SkuPriceSellerRelationDTO>> querySkuPrice(SkuPriceRequest request) {
        try {
            List<SkuPriceSellerRelationDTO> skuPriceSellerRelationDTOS = skuPriceSellerRelationService.querySkuPrice(request);
            return JsonResult.buildSuccess(skuPriceSellerRelationDTOS);
        } catch (ProductBizException e) {
            log.error("biz error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
